/**
 * 
 */
package UnitTests;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import RefactoringA1.src.SavingsAccount;

/**
 * @author Thomas
 *
 */
public class SavingsAccountTest {

	
	SavingsAccount sa;

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		sa = new SavingsAccount("Bobby", "Maple", "98500", "Anytown", "usa");
	}

	/**
	 * Test method for {@link RefactoringA1.src.SavingsAccount#SavingsAccount(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)}.
	 */
	@Test
	public void testSavingsAccount() {
		Assert.assertTrue(sa instanceof SavingsAccount);
	}

	/**
	 * Test method for {@link RefactoringA1.src.SavingsAccount#calculateInterest()}.
	 * 
	 * Cannot properly test this method because it returns void and the affected fields
	 * are private with no getters.
	 */
	@Test
	public void testCalculateInterest() {
		sa.calculateInterest();
		Assert.assertTrue(true);
	}

	/**
	 * Test method for {@link RefactoringA1.src.SavingsAccount#withdrawal(double)}.
	 */
	@Test
	public void testWithdrawal() {
		Assert.assertTrue(sa.withdrawal(0));
		Assert.assertFalse(sa.withdrawal(10.00));
	}

	/**
	 * Test method for {@link RefactoringA1.src.SavingsAccount#verseMoney(double)}.
	 * 
	 * Cannot properly test this method because it returns void and the affected fields
	 * are private with no getters.
	 */
	@Test
	public void testVerseMoney() {
		sa.verseMoney(10.00);
		Assert.assertTrue(true);
	}

	/**
	 * Test method for {@link RefactoringA1.src.SavingsAccount#print()}.
	 */
	@Test
	public void testPrint() {
		final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
		System.setOut(new PrintStream(outContent));
		sa.print();
		String printResults = outContent.toString();
		System.setOut(null);

		final ByteArrayOutputStream outContent2 = new ByteArrayOutputStream();
		System.setOut(new PrintStream(outContent2));
		sa.print();
		String printResults2 = outContent2.toString();
		System.setOut(null);

		Assert.assertEquals(printResults, printResults2);

	}

	/**
	 * Test method for {@link java.lang.Object#Object()}.
	 */
	@Test
	public void testObject() {
		Assert.assertTrue(sa instanceof SavingsAccount);
	}

	/**
	 * Test method for {@link java.lang.Object#getClass()}.
	 */
	@Test
	public void testGetClass() {
		Assert.assertTrue(sa.getClass().getSimpleName().equals("SavingsAccount"));
	}

	/**
	 * Test method for {@link java.lang.Object#equals(java.lang.Object)}.
	 */
	@Test
	public void testEquals() {
		SavingsAccount sa2 = new SavingsAccount("Bob", "Map", "98506", "Antown", "russia");
		Assert.assertEquals(sa, sa);
		Assert.assertFalse(sa.equals(sa2));
	}
	
	@After
	public void cleanUpStreams() {
	    System.setOut(null);
	}

}
